package cn.edu.sjtu.literature.web.controller;

import java.util.HashMap;
import java.util.Map;

public class DefaultControllerFactory implements ControllerFactory {

	private static DefaultControllerFactory controllerFactory = new DefaultControllerFactory();
	
	private Map<String, Controller> controllers = new HashMap<String, Controller>();
	
	private DefaultControllerFactory() {
		controllers.put("/loginForm", new InitLoginFormController());
		controllers.put("/login", new LoginController());
		controllers.put("/logout", new LogoutController());
		controllers.put("/homepage", new LoggedInControllerWrapper(new HomepageController()));
		controllers.put("/literatureForm", new AdministratorControllerWrapper(new InitLiteratureFormController()));
		controllers.put("/saveLiterature", new AdministratorControllerWrapper(new LiteratureSavingController()));
		controllers.put("/literatureQueryForm", new LoggedInControllerWrapper(new InitLiteratureQueryFormController()));
		controllers.put("/queryLiterature", new LoggedInControllerWrapper(new LiteratureQueryController()));
		controllers.put("/literatureExportForm", new AdministratorControllerWrapper(new InitLiteratureExportFormController()));
		controllers.put("/exportLiterature", new AdministratorControllerWrapper(new LiteratureExportController()));
		controllers.put("/literatureImportForm", new AdministratorControllerWrapper(new InitLiteratureImportFormController()));
		controllers.put("/importLiterature", new AdministratorControllerWrapper(new LiteratureImportController()));
	}
	
	public static DefaultControllerFactory getInstance() {
		return controllerFactory;
	}
	
	public Controller getController(String uri) {
		return controllers.get(uri);
	}
	
}
